//
//  TthereToastController.m
//  OnionHome
//
//  Created by fengjie on 2019/9/18.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "TthereToastController.h"
#import "FrouToastController.h"

@interface TthereToastController ()<UITableViewDelegate,UITableViewDataSource>
/**listView*/
@property (nonatomic,strong)UITableView*listView;
/**数据源*/
@property (nonatomic,strong)NSMutableArray*dataSoure;

/**搜索视图*/
@property (nonatomic,strong)UITextField*serachField;

@end

@implementation TthereToastController

- (void)viewDidLoad {
    [super viewDidLoad];
    ViewRadius(self.view, 4);
    [self createUI];
}
-(void)createUI{
    self.isHidenNaviBar = YES;
    self.view.backgroundColor = UIColorFromRGB(0xE9EEE7);
    
    UIView * view = [self createHeaderView];
    view.backgroundColor = KWhiteColor;
    
    UIView * searchView = [self createSerbar];

    
    [self.view addSubview:self.listView];
    [self.view addSubview:view];
    [self.view addSubview:searchView];
    
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(0);
        make.height.mas_equalTo(50);
    }];
    
    [self.listView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.bottom.mas_equalTo(-50);
        make.top.mas_equalTo(view.mas_bottom).offset(0.5);
    }];
    [searchView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.mas_equalTo(0);
        make.top.mas_equalTo(self.listView.mas_bottom);
//        make.bottom.mas_equalTo(-16);
    }];

}
#pragma mark ---UITableViewDelegate,UITableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataSoure.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([UITableViewCell class])];
//    cell.textLabel.textColor = UIColorFromRGB(0x273323);
//    cell.textLabel.font = SYSTEMFONT(14);
//    cell.textLabel.text = self.dataSoure[indexPath.row];
    cell.textLabel.attributedText = self.dataSoure[indexPath.row];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return (290 - 50)/4;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [self backBtnClicked];
}
-(UITableView*)listView{
    if(!_listView){
        _listView=[UITableView new];
        _listView.delegate =self;
        _listView.dataSource = self;
        _listView.scrollEnabled = NO;
        _listView.rowHeight = UITableViewAutomaticDimension;
        _listView.estimatedRowHeight = 44.0f;

        [_listView registerClass:[UITableViewCell class] forCellReuseIdentifier:NSStringFromClass(UITableViewCell.class)];
        _listView.separatorColor = SeparatorColor;
        _listView.separatorInset = UIEdgeInsetsMake(0, 16, 0, 16);
    }
    return _listView;
}
-(NSMutableArray *)dataSoure{
    if (!_dataSoure) {
        _dataSoure =[[NSMutableArray alloc] init];
//        WithObjects:@"屏蔽：薯条",@"屏蔽：垃圾食品",@"屏蔽：关键词", nil
        NSMutableAttributedString * oneAtt = [self getItemWithLeftTitle:@"屏蔽：" RightTitle:@"薯条"];
        NSMutableAttributedString * twoAtt = [self getItemWithLeftTitle:@"屏蔽：" RightTitle:@"垃圾食品"];
        NSMutableAttributedString * thereAtt = [self getItemWithLeftTitle:@"屏蔽：" RightTitle:@"关键词"];
        [_dataSoure addObject:oneAtt];
        [_dataSoure addObject:twoAtt];
        [_dataSoure addObject:thereAtt];

    }
    return _dataSoure;
}
-(NSMutableAttributedString *)getItemWithLeftTitle:(NSString *)leftTitle RightTitle:(NSString *)rightTitle{
    
    NSMutableAttributedString * atrr = [NSMutableAttributedString makeAttributeString:leftTitle Attribute:^(NSMutableDictionary * _Nonnull attributes) {
        [attributes setValue:BOLDSYSTEMFONT(14) forKey:NSFontAttributeName];
        attributes.Color(KBlackColor);
    }];
    [atrr makeAttributeStringAdd:rightTitle Attribute:^(NSMutableDictionary * _Nonnull attributes) {
        attributes.Font(14).Color(KBlackColor);
    }];

    return atrr;
}
-(UIView *)createHeaderView{
    UIView * view = UIView.new;
    
    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setBackgroundImage:IMAGE_NAMED(@"back") forState:UIControlStateNormal];
    kWeakSelf(weakSelf);
    [button addActionHandler:^{
        [weakSelf.navigationController popViewControllerAnimated:YES];
    }];
    

    UILabel * label = UILabel.new;
    label.text = @"屏蔽";
    label.textAlignment = NSTextAlignmentCenter;
    label.font = SYSTEMFONT(16);
    label.textColor = UIColorFromRGB(0x273323);
    
    [view addSubview:button];
    [view addSubview:label];
    
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.centerY.mas_equalTo(0);
    }];
    
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(0);
    }];
    
    return view;
}

-(UIView * )createSerbar{
    UIView * view = UIView.new;
    view.backgroundColor = UIColor.whiteColor;
    
    UIView * view1 = UIView.new;
    view1.backgroundColor = UIColorFromRGB(0xF5F7F5);
    ViewRadius(view1, 4);
    
    [view addSubview:view1];
    
    [view1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.centerY.mas_equalTo(0);
        make.right.mas_equalTo(-16);
        make.height.mas_equalTo(38);
    }];
    
    UIImageView * leftImage = [[UIImageView alloc] initWithImage:IMAGE_NAMED(@"xiepinglun")];
    [view1 addSubview:leftImage];
    [view1 addSubview:self.serachField];
    
    
    [leftImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.left.mas_equalTo(8);
        make.width.height.mas_equalTo(20);
    }];
    
    [self.serachField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.left.mas_equalTo(leftImage.mas_right).offset(4);
        make.top.right.bottom.mas_equalTo(0);
    }];
    
    
    return view;
}

-(UITextField*)serachField{
    if(!_serachField){
        _serachField=[UITextField new];
        _serachField.placeholder = @"我要吐糟...";
        _serachField.placeholderColor = UIColorFromRGB(0x454F44);
        _serachField.placeholderFont = SYSTEMFONT(14);
        _serachField.userInteractionEnabled = YES;
        
        [_serachField addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction)]];
    }
    return _serachField;
}
-(void)tapAction{
    PresentationObject * object = [PresentationObject sharedPresentationObject];
    object.alpha_bgView = 1;
    object.subViewFrame = CGRectMake(0, KScreenHeight-240, KScreenWidth, 240);
    FrouToastController * vc = [FrouToastController new];
    kWeakSelf(weakSelf);
    vc.releseBlock = ^{
        [weakSelf.navigationController dismissViewControllerAnimated:NO completion:nil];
    };
    [object showPresentingViewController:self PresentedViewController:vc];

}
@end
